在MATLAB的Simulink中有些常用的模块,今天主要介绍常数模块、示波器模块、以及模块属性的操作函数。 1.模块的构成元素输入/输出端口:作为模块之间传递数据的纽带,连接输入信号和输出信号。
模块外观:通常为矩形或圆形,上面带有说明文字或图像并显示有输出
/输出端口名。
模块对话框:双击模块外观后弹出的参数GUI,可以在参数控件上进行参数设置。2.Matlab/Simulink快捷键2.1 模型调整Alt + Enter:为选定模块设置主要参数
Ctrl + Shift + I:打开或隐藏 Property Inspector
Shift + 拖动句柄:调整模块大小,保持相同的高宽比
Ctrl + 拖动句柄:从中心调整模块大小
Ctrl + R:顺时针旋转模块 顺时针旋转90°
Ctrl + Shift + R:逆时针旋转模块
Ctrl + I:翻转模块
Ctrl + F:查找模块
Ctrl + M:封装模块
Ctrl + U:在模块封装下查找
Ctrl + Shift + Y:注释模块
Ctrl + Shift + X:注释掉或取消注释模块
Ctrl + K:刷新Mode模块
Ctrl + L:对于链接模块,转到父模块的库
Ctrl + H:打开 Model Explorer2.2 仿真键盘快捷键Ctrl + E:打开 Configuration Parameters对话框
Ctrl + D:更新图
Ctrl + T:开始仿真
Ctrl + Shift + T:停止仿真
Ctrl + B:构建模型(用于代码生成)2.3 调试和断点键盘快捷方式F10:步骤
F11:步入
Shift + F11:步出
F5:运行
F12:设置/清除断点
Ctrl + J:查看simple time
视图放大:r
视图缩小:v3.模块的常用属性和参数 clc;
clear all;
close all;
% 获取模块的属性
% gcb:获取当前被选中的模块
% gcbh:获取当前被选中的模块的句柄
% get(handle):获取模块的属性信息
% inspect(handle):通过属性观察器方式罗列模块的属性信息
% get_param(block,prop_string):获取block模块的prop_string属性值
% set_param(block,prop_string,prop_value):将block模块的prop_string属性的值设为
% prop_value。prop_string,prop_value可以多对出现
open_system('test1')
information = gcb
get(gcbh)
set_param(gcbh,'BackgroundColor','c')
set_param(gcbh,'ForegroundColor','blue')
%set_param/get_param的第二个参数使用的不是提示标签,而是参数的变量名。
information =
'test1/Scope'
Path: 'test1'
Name: 'Scope'
Tag: ''
Description: ''
Type: 'block'
Parent: 'test1'
Handle: 4.0430e+03
HiliteAncestors: 'none'
RequirementInfo: ''
FontName: 'auto'
FontSize: -1
FontWeight: 'auto'
FontAngle: 'auto'
Selected: 'on'
MaskType: ''
MaskDescription: ''
MaskHelp: ''
MaskPromptString: ''
MaskStyleString: ''
MaskVariables: ''
MaskTunableValueString: ''
MaskCallbackString: ''
MaskEnableString: ''
MaskVisibilityString: ''
MaskToolTipString: ''
MaskVarAliasString: ''
MaskInitialization: ''
MaskSelfModifiable: 'off'
MaskDisplay: ''
MaskBlockDVGIcon: ''
MaskIconFrame: 'on'
MaskIconOpaque: 'opaque'
MaskIconRotate: 'none'
MaskPortRotate: 'default'
MaskIconUnits: 'autoscale'
MaskValueString: ''
MaskRunInitForIconRedraw: 'analyze'
MaskTabNameString: ''
Mask: 'off'
MaskCallbacks: {0×1 cell}
MaskEnables: {0×1 cell}
MaskNames: {0×1 cell}
MaskPropertyNameString: ''
MaskPrompts: {0×1 cell}
MaskStyles: {0×1 cell}
MaskTunableValues: {0×1 cell}
MaskValues: {0×1 cell}
MaskToolTipsDisplay: {0×1 cell}
MaskVisibilities: {0×1 cell}
MaskVarAliases: {0×1 cell}
MaskWSVariables: []
MaskTabNames: {0×1 cell}
MaskObject: []
Ports: [1 0 0 0 0 0 0 0 0]
Position: [345 129 375 161]
Orientation: 'right'
PortRotationType: 'default'
ForegroundColor: 'black'
BackgroundColor: 'cyan'
DropShadow: 'off'
IOType: 'none'
NamePlacement: 'normal'
ShowName: 'on'
HideAutomaticName: 'on'
Priority: ''
Commented: 'off'
CodeProfilingOverride: 'inherit'
AttributesFormatString: ''
InstantiateOnLoad: 'off'
PolySpaceEndComment: ''
PolySpaceStartComment: ''
AncestorBlock: ''
ReferenceBlock: ''
SourceLibraryInfo: ''
LibraryVersion: ''
UserDataPersistent: 'off'
UserData: []
CompiledIsActive: 'on'
RTWdata: []
HDLData: []
Diagnostics: ''
DialogParameters: [1×1 struct]
IntrinsicDialogParameters: [1×1 struct]
AlgorithmParameters: [1×1 struct]
SecondaryAlgorithmParameters: [1×1 struct]
CompiledSampleTime: [-1 0]
InputSignalNames: {''}
OutputSignalNames: {1×0 cell}
ModelParamTableInfo: []
StatePerturbationForJacobian: '1.0e-05'
SCDEnableBlockLinearizationSpecification: 'off'
SCDBlockLinearizationSpecification: []
CopyFcn: ''
DeleteFcn: ''
UndoDeleteFcn: ''
LoadFcn: ''
ModelCloseFcn: ''
PreSaveFcn: ''
PostSaveFcn: ''
InitFcn: ''
StartFcn: ''
PauseFcn: ''
ContinueFcn: ''
StopFcn: ''
NameChangeFcn: ''
ClipboardFcn: ''
DestroyFcn: ''
PreCopyFcn: ''
OpenFcn: ''
CloseFcn: ''
PreDeleteFcn: ''
ParentCloseFcn: ''
MoveFcn: ''
BlockType: 'Scope'
BlockDescription: 'Displays input signals with respect to simulation time'
BlockKeywords: ""
LinkStatus: 'none'
StaticLinkStatus: 'none'
PortConnectivity: [1×1 struct]
PortHandles: [1×1 struct]
LineHandles: [1×1 struct]
CompiledPortWidths: [0×0 struct]
CompiledPortDimensions: [0×0 struct]
CompiledPortDataTypes: [0×0 struct]
CompiledPortUnits: [0×0 struct]
CompiledPortComplexSignals: [0×0 struct]
CompiledPortFrameData: [0×0 struct]
DataTypeOverride_Compiled: 'UseLocalSettings'
MinMaxOverflowLogging_Compiled: 'UseLocalSettings'
Capabilities: [1×1 Capabilities]
IOSignalStrings: []
RuntimeObject: [0×1 double]
ExtModeUploadOption: 'none'
ExtModeLoggingSupported: 'on'
ExtModeLoggingTrig: 'off'
TargetArchitectureMapping: {}
OpenAtSimulationStart: 'off'
DisplayFullPath: 'off'
NumInputPorts: '1'
LayoutDimensionsString: '[1 1]'
SampleTime: '-1'
FrameBasedProcessingString: 'Elements as channels (sample based)'
MaximizeAxes: 'Off'
AxesScaling: 'Manual'
AxesScalingNumUpdates: '10'
TimeSpan: 'Auto'
TimeSpanOverrunAction: 'Wrap'
TimeUnits: 'None'
TimeDisplayOffset: '0'
TimeAxisLabels: 'Bottom displays only'
ShowTimeAxisLabel: 'off'
ActiveDisplayString: '1'
Title: '%'
ShowLegend: 'off'
ShowGrid: 'on'
PlotAsMagnitudePhase: 'off'
ActiveDisplayYMinimum: '-10'
ActiveDisplayYMaximum: '10'
YLabel: ''
DataLoggingLimitDataPoints: 'off'
DataLoggingMaxPoints: '5000'
DataLoggingDecimateData: 'off'
DataLoggingDecimation: '2'
DataLogging: 'off'
DataLoggingVariableName: 'ScopeData'
DataLoggingSaveFormat: 'Dataset'
>> 模块的常用属性 属性名 作用说明
Path 模块在模型中的路径
Name 模块的名字
ShowName 模块的名字是否显示出来
BlockType 模块的类型名
Handle 模块的句柄,double数据表示
Position 模块的边框在当前模型中的位置
ForegroundColor 模块的前景色
BackgroundColor 模块的背景色
Sample Time 模块的采样时间
FontAngle 字体斜度
FontName 字体名
FontSize 字体大小
FontWeight 字体粗度4.常量模块常数模块在仿真过程中通常输出恒定的数值。常数模块不仅支持scalar数据作为参数输入,也支持向量、矩阵等多维数据。 提示标签 参数的变量名
Constant value 价值
Interpret vector parameters as 1-D 将向量参数解释为1-D
Sampling mode 采样模型
Sample time 采样时间 常数模块、加减乘除四则运算和增益模块及输入输出端口都拥有
Signal Attributes属性配置界面。 Output minimum和Output maximum中默认为空,不对数据输出进行任何检测。
一旦设置了数值,模块就会对输出值进行检查,当数值小于Output minimum
或者大于Output maximum时就会报错来提醒用户。
Output data type对输出数据的类型提供了一些选项。5.示波器模块Scope模块是示波器模块,能够显示实数信号线。 ![](data:image/svg+xml;utf8,svg%20xmlns='http://www.w3.org/2000/svg'%20width='520'%20height='420'/svg) ![](data:image/svg+xml;utf8,svg%20xmlns='http://www.w3.org/2000/svg'%20width='1002'%20height='658'/svg) (1) 修改Scope的输入端口个数 双击示波器模块,点击File->-Number of input ports,修改输入端口的个数为3。 ![](data:image/svg+xml;utf8,svg%20xmlns='http://www.w3.org/2000/svg'%20width='702'%20height='628'/svg) ![](data:image/svg+xml;utf8,svg%20xmlns='http://www.w3.org/2000/svg'%20width='1002'%20height='658'/svg) (2)修改示波器的显示布局的个数 点击View->Configureation Properties->Number of input ports,将1修改成3。 ![](data:image/svg+xml;utf8,svg%20xmlns='http://www.w3.org/2000/svg'%20width='1140'%20height='710'/svg) ![](data:image/svg+xml;utf8,svg%20xmlns='http://www.w3.org/2000/svg'%20width='702'%20height='628'/svg) (3)将示波器的数据输出 点击View->点击Configureation Properties->点击Logging->勾选Log data to workspace。 可以设置变量名(Variable name),选择存储到workspace中的存储格式。
1.Structure With Time将Scope获取到的采样信号存储在结构体中,
这个结构体包括:
(1)存储时间序列的time
(2)存储对应采样时间点的采样数据以及相关信息的结构体signals
(3)存储模块全路径及名字的变量blockName
signals本身也是一个结构体,访问采样数据的方式
是ScopeData.signals.values,采样数据按列排布。
ScopeData.time 存储时间序列的time
ScopeData.signals.values 存储对应采样时间点的采样数据。
2.Structure存储类型少了time这个时间序列的存储,其他成员相同。
3.Array为列向量方式存储。
4.dataset 为数据集数组用于将异构数据和元数据(包括变量和观察名称)
收集到单个容器变量中。数据集数组适合存储面向列的数据或表格数据,
这些数据通常以列的形式存储在文本文件或电子表格中,并且可以容纳
不同类型、大小、单位等的变量。![](data:image/svg+xml;utf8,svg%20xmlns='http://www.w3.org/2000/svg'%20width='1140'%20height='710'/svg) (4)示波器的动态参数和光标 ![](data:image/svg+xml;utf8,svg%20xmlns='http://www.w3.org/2000/svg'%20width='1002'%20height='658'/svg) Bilevel Measurements:用于测量输入信号的过渡时间、超调、负调及周期。 ![](data:image/svg+xml;utf8,svg%20xmlns='http://www.w3.org/2000/svg'%20width='702'%20height='628'/svg) Cursor Measurements:用于光标测量。 ![](data:image/svg+xml;utf8,svg%20xmlns='http://www.w3.org/2000/svg'%20width='702'%20height='628'/svg) Signal Statistics:信号的统计数据。 ![](data:image/svg+xml;utf8,svg%20xmlns='http://www.w3.org/2000/svg'%20width='702'%20height='628'/svg) Peak Finder:峰值查找器 ![](data:image/svg+xml;utf8,svg%20xmlns='http://www.w3.org/2000/svg'%20width='702'%20height='628'/svg) (5)修改示波器坐标轴粗细、颜色、名称、图例、图形颜色、标记点类型。 点击view->点击style或者Legend设置图例 ![](data:image/svg+xml;utf8,svg%20xmlns='http://www.w3.org/2000/svg'%20width='702'%20height='628'/svg) ![](data:image/svg+xml;utf8,svg%20xmlns='http://www.w3.org/2000/svg'%20width='702'%20height='628'/svg) (6)将示波器图像转化为Figure,保存为其他格式图像文件。 点击File-> print to Figure ![](data:image/svg+xml;utf8,svg%20xmlns='http://www.w3.org/2000/svg'%20width='1080'%20height='488'/svg) (7)给示波器添加编辑选项,编程方式设置 Scope波形显示模块实际上也是一个Figure窗口,隐藏了菜单栏的属性,可以通过程序设置菜单栏,执行以下程序。 set(0,'ShowHiddenHandles','On')
set(gcf,'menubar','figure')或者运行以下程序 shh = get(0,'ShowHiddenHandles');
set(0,'ShowHiddenHandles','On')
set(gcf,'menubar','figure')
set(gcf,'CloseRequestFcn','closereq')
set(gcf,'DefaultLineClipping','Off')
set(0,'ShowHiddenHandles',shh) 参考内容[1] 博客园作者叮叮当当sunny的文章《Simulink仿真入门到精通(二) Simulink模块 》,文章链接如下:https://www.cnblogs.com/dingdangsunny/p/12235689.html#_label0 [2] CSDN博主「小曾&同学」的文章《Matlab/Simulink快捷键》,文章链接如下: https://blog.csdn.net/acknole/article/details/112344263 [3] CSDN博主 gameboy12615的文章《Matlab 示波器显示设置》,文章链接为: https://blog.csdn.net/gameboy12615/article/details/6056390?locationNum=14 本文内容来源于网络,仅供参考学习,如内容、图片有任何版权问题,请联系处理,24小时内删除。 作 者 | 郭志龙 编 辑 | 郭志龙校 对 | 郭志龙
|